﻿
Imports System.Data
Imports System.Web.UI.WebControls
Imports System.Text
Imports System.Web.UI
Imports Mysoft.PubProject.Business

Partial Class Cwjk_SetHsxm_Map2
    Inherits Mysoft.Map.Application.Security.AppPage

#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region

#Region "Repeater初始化函数"
    Private Sub Data_Bind()
        Dim sProjGUID As String = ""
        Dim sFilter As String = ""
        Dim myGetMap As New CwjkMNG

        '查询语句
        Select Case Trim(sOperObject)
            Case "入账银行"
                Exit Select
            Case "预约单"
                sProjGUID = Request.QueryString("projguid")
                Exit Select
        End Select

        '自定义控件绑定数据
        Repeater1.BindMode = 1                                          '绑定模式：0 -- SQL 语句绑定，1 -- DataTable 绑定
        Repeater1.PKField = "HsxmMapGUID"
        Repeater1.DataTable = myGetMap.GetKjkmOrHsxmDT("HSXM", Session("BUGUID"), txtCwztGUID.Text, sProjGUID, sOperObject, "", txtKmTypeGUID.Text, txtApplication.Text, sFilter)
        Repeater1.DataBind()                                            '绑定数据


    End Sub

    Private Sub Yyd_Data_Bind()
        Dim sProjGUID As String = ""
        Dim sFilter As String = ""
        Dim sObjectName As String = ""
        Dim dtTmp As DataTable
        Dim myGetMap As New CwjkMNG


        sProjGUID = Request.QueryString("projguid")

        dtTmp = myGetMap.GetKjkmOrHsxmDT("HSXM", Session("BUGUID"), txtCwztGUID.Text, sProjGUID, sOperObject, "", txtKmTypeGUID.Text, txtApplication.Text, sFilter)

        '设置核算代码、核算名称
        If dtTmp.Rows.Count > 0 Then
            Dim i As Integer
            If txtRptRule.Text = "ALL" Then                 '全部替换
                For i = 0 To dtTmp.Rows.Count - 1
                    If Trim(txtHsType.Text) <> "" Then dtTmp.Rows(i).Item("HsxmSort") = txtHsType.Text
                    sObjectName = dtTmp.Rows(i).Item("ObjectName").ToString
                    Dim myArry() As String = sObjectName.Split("：")

                    dtTmp.Rows(i).Item("HsxmCode") = myArry(0) & myGetMap.PinYin(myArry(1)).ToUpper
                    dtTmp.Rows(i).Item("HsxmName") = myArry(1)
                Next
            Else                                            '只替换为空的记录
                For i = 0 To dtTmp.Rows.Count - 1
                    If Trim(txtHsType.Text) <> "" AndAlso Trim(dtTmp.Rows(i).Item("HsxmSort").ToString) = "" Then dtTmp.Rows(i).Item("HsxmSort") = txtHsType.Text
                    sObjectName = dtTmp.Rows(i).Item("ObjectName").ToString
                    Dim myArry() As String = sObjectName.Split("：")

                    If Trim(dtTmp.Rows(i).Item("HsxmCode").ToString) = "" Then dtTmp.Rows(i).Item("HsxmCode") = myArry(0) & myGetMap.PinYin(myArry(1)).ToUpper
                    If Trim(dtTmp.Rows(i).Item("HsxmName").ToString) = "" Then dtTmp.Rows(i).Item("HsxmName") = myArry(1)
                Next
            End If
        End If

        '自定义控件绑定数据
        Repeater1.BindMode = 1                                          '绑定模式：0 -- SQL 语句绑定，1 -- DataTable 绑定
        Repeater1.PKField = "HsxmMapGUID"
        Repeater1.DataTable = dtTmp
        Repeater1.DataBind()                                            '绑定数据
    End Sub
#End Region

    Dim sCwztGUID, sKmtypeGUID, sOperObject, sOpenRoot As String

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sApplication As String
        sApplication = Request.QueryString("Application")
        txtApplication.Text = Trim(sApplication)
        Repeater1.EnablePager = True
        sCwztGUID = Request.QueryString("cwztguid")
        sKmtypeGUID = Request.QueryString("kmtypeguid")
        sOperObject = Request.QueryString("operobject")
        sOpenRoot = Request.QueryString("openroot")
        If Not IsPostBack Then
            txtCwztGUID.Text = Trim(sCwztGUID)
            txtKmTypeGUID.Text = Trim(sKmtypeGUID)
            txtOperObject.Text = Trim(sOperObject)
            txtOpenRoot.Text = Trim(sOpenRoot)

            Data_Bind()
        Else

            '前端：         __doPostBack(__EVENTTARGET, __EVENTARGUMENT);
            Dim strEventTgt As String = Trim(Request.Form("__EVENTTARGET"))
            Dim strEventArg As String = Trim(Request.Form("__EVENTARGUMENT"))
            Select Case strEventTgt.ToUpper
                Case "REFRESH"                        '修改后刷新显示
                    Data_Bind()
                    Exit Select
                Case Else
                    If Trim(sOperObject) = "预约单" And txtPinYinCale.Text <> "SAVEOK" Then
                        Yyd_Data_Bind()
                    Else
                        Data_Bind()
                        txtPinYinCale.Text = ""
                    End If
            End Select
        End If

    End Sub

End Class
